﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Epona.Domain.Query.Impl
{
    public class AndCriterion:AbstractCriterion
    {
        public ICollection<IQueryCriterion> Criterions { private set; get; }

        public AndCriterion(params IQueryCriterion[] criterions)
        {
            this.Criterions = RemoveNullOrEmptyCriterion(criterions);
        }

        public override string ToQueryString()
        {
            List<string> subCriterionStr = new List<string>();
            foreach(IQueryCriterion each in Criterions)
            {
                subCriterionStr.Add(each.ToQueryString());
            }
            return string.Join(" and ", subCriterionStr);
        }

        public override NamedParameters GetParameters()
        {
            NamedParameters result = NamedParameters.Create();
            foreach(IQueryCriterion each in Criterions)
            {
                result.Add(each.GetParameters());
            }
            return result;
        }
    }
}
